package handlers

import (
	"github.com/gin-gonic/gin"
	"stat-plat/models"
	"strconv"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
	size, _ := strconv.Atoi(c.DefaultQuery("size", "3"))

	offset := (page - 1) * size

	var count int64
	models.DB.Model(&models.User{}).Count(&count)

	var user []models.User
	err := models.DB.Order("ID desc").Offset(offset).Limit(size).Find(&user).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "查询失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": gin.H{
			"count": count,
			"user":  user,
		},
	})
	return

}
